#pragma once

#include "cocos2d.h"
#include "LightPlayer.h"
#include "LightFile.h"
#include "LightAbstractRenderer.h"
#include "ccTypes.h"
#include "shaders\CCGLProgram.h"

using namespace LightPlayer;

class LightRendererGL : public LightAbstractRenderer {
	array<cocos2d::CCTexture2D*>		m_Textures;
	float								m_Color[4];
	float								m_PointSize;
	uint32								m_MaskStack;
	array<CXFORM>						m_CXFormStack;


	// shader
	cocos2d::CCGLProgram				m_Shader;
	// shader choice
	int u_ActiveShader;			
	// simple color
	int u_color;				
	// cx form
	int u_use_cxform;					
	int u_cxform_mult_color;				
	int u_cxform_add_color;			
	// gradient 
	int u_ColorControl;			
	int u_RatioControl;				
	int u_isLinear;				
public:
	LightRendererGL();

	void init();

	virtual void beginDraw();
	virtual void endDraw();

	virtual void pushMatrix( const MATRIX& transform );
	virtual void DrawLine( const vec2& origin, const vec2& destination );
	virtual void DrawQuadBezier(const vec2& origin, const vec2& control, const vec2& destination, uint32 segments);
	virtual void DrawPoint( const vec2& point );
	virtual void DrawSolidTris( const array<vec2>& Tris );
	virtual void DrawSolidTrisTextured( const array<vec2>& Tris, const array<vec2>& UVs, uint32 texture );
	virtual void DrawSolidTrisGradient( const array<vec2>& Tris, const array<vec2>& UVs, const GRADIENT& Gradient );
	virtual void popMatrix();

	// mask 
	virtual void PushMask_Start();
	virtual void PushMask_End();
	virtual void PopMask_Start();
	virtual void PopMask_End();

	virtual void setCurrentColor(float r, float g, float b, float a);
	virtual void setPointSize( float pointSize );

	virtual void pushCXFORM(const CXFORM& new_cxform, bool use_stack_transform = true);
	virtual void popCXFORM();

	virtual uint32 createTextureFromRowData( uint8* _rowData, uint32 width, uint32 height );

private:
	void refresh_MVP_Uniform();
	void refresh_Color_Uniform();
	void refresh_CXForm_Uniform();
};